cmake: Use -idirafter instead of -isystem #777
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
isystem dirs are searched before the regular system dirs this exposes an interesting include ordering problem when using clang + libc++, when including C++ headers like
cstdlib includes stdlib.h and in case of libc++, this should be coming from libc++ as well, which is then eventually including system stdlib.h
libc++ has added a check for checking this order recently, which means if cstlib ends up including system stdlib.h before libc++ provided stdlib.h it errors out
| /mnt/b/yoe/master/build/tmp/work/riscv64-yoe-linux/libcereal/1.3.2+gitAUTOINC+ebef1e9298-r0/recipe-sysroot/usr/include/c++/v1/cwchar:113:5: error: tried including <wchar.h> but didn't find libc++'s header. This usually means that your header search paths are not configured properly. The header search paths should contain the C++ Standard Library headers before any C Standard
Library, and you are probably using compiler flags that make that not be the case. | # error tried including <wchar.h> but didn't find libc++'s <wchar.h> header.
| ^
The reason is that include_directories with SYSTEM property adds the directory via -system and some of these directories point to sysroot e.g. OPENSSL_INCLUDE_DIR which ends up adding -isystem /usr/include and causes the system stdlib.h to included before libc++ stdlib.h
A fix is to use -idirafter which preserved the effects of system headers but instead of prepending, it will append to system headers and the issue is addressed
Signed-off-by: Khem Raj [email protected]